package com.itany.corejava.code14_lambda;

import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * @author MissChen
 * @date 2024年03月25日 16:20
 */
public class Test07_构造方法的引用 {
    public static void main(String[] args) {
        // Supplier<User> s=new Supplier<User>() {
        //     @Override
        //     public User get() {
        //         return new User();
        //     }
        // };
        // System.out.println(s.get());

        User user=new User();


        //调用无参构造方法
        Supplier<User> s=User::new;
        System.out.println(s.get());

        // User user2=new User("admin");
        Function<String,User> f=User::new;
        System.out.println(f.apply("coco"));


        // 调用2个参数的构造方法
        User user3=new User("admin","123456");
        BiFunction<String,String,User> bf=User::new;
        System.out.println(bf.apply("aa","123"));

        AA<String,Stu> aa=Stu::new;
        System.out.println(aa.cal("admin","123","上海"));

    }
}

//自定义函数式接口
@FunctionalInterface
interface AA<T,R>{
    R cal(T t1,T t2,T t3);
}
class Stu{
    private String username;
    private String password;
    private String address;

    public Stu(String username, String password, String address) {
        this.username = username;
        this.password = password;
        this.address = address;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    @Override
    public String toString() {
        return "Stu{" +
                "username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", address='" + address + '\'' +
                '}';
    }
}